package com.uenpay.im.ui.old.activity.funds;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-3-22 下午6:56:47
 * @copyRight http://www.qiyunxin.com
 * @function 添加经费支出
 */
public class AddChatFeeTurnoverInvokeItem extends BaseHttpInvokeItem {

	public class AddChatFeeTurnoverInvokeItemResult extends HttpInvokeResult {
	}

	public AddChatFeeTurnoverInvokeItemResult getOutPut() {
		return (AddChatFeeTurnoverInvokeItemResult) GetResultObject();
	}

	/**
	 * 添加群经费记录
	 * 
	 * @param chatid
	 * @param custid
	 *            收款对象用户id(可为空)
	 * @param amount
	 * @param content
	 * @param direction
	 *            收支(1为收入，2为支出)
	 */
	public AddChatFeeTurnoverInvokeItem(String chatid, String custid,
			String amount, String content, int direction) {
		String url = APIConfiguration.getBaseUrl()
				+ "Chat/SpecialChat/addChatFeeTurnover?chatid=" + chatid
				+ "&custid=" + custid + "&amount=" + amount + "&content="
				+ content + "&direction=" + direction + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		AddChatFeeTurnoverInvokeItemResult result = new AddChatFeeTurnoverInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");

		return result;
	}

}
